package dk.simonvogensen.itodo.client.model;

import com.google.gwt.user.client.rpc.IsSerializable;

import java.util.List;

/**
 * @author $LastChangedBy: vogensen@gmail.com $ $LastChangedDate: 2009-03-20 08:45:15 +0100 (Fri, 20 Mar 2009) $
 * @version $Revision: 12 $
 */
public class ProjectId implements IsSerializable {

    private String name;

    public ProjectId() {
    }

    public ProjectId(String name) {
        this.name = name;
    }

    public String getName() {
        return name;
    }

    public static ProjectId contains(String s, List<ProjectId> projectIds) {
        for (ProjectId pi : projectIds) {
            if (s.contains(pi.getName())) return pi;
        }
        return null;
    }

    public static ProjectId containsProject(String s, List<ProjectId> projectIds) {
        for (ProjectId pi : projectIds) {
            if (s.matches("^-\\s" + pi.getName() + "\\s.*$")) return pi;
        }
        return null;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        ProjectId projectId = (ProjectId) o;

        if (name != null ? !name.equals(projectId.name) : projectId.name != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        return result;
    }
}
